package test.org.jrfe;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class InversYAxis extends JPanel{

	
	BufferedImage img;
	
	public InversYAxis() {
		try {
			img = ImageIO.read(this.getClass().getClassLoader().getResource("data/B.png"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
	
		Graphics2D g2 = (Graphics2D)g;
		AffineTransform  T= g2.getTransform();
		try {
			T.createInverse();
		} catch (NoninvertibleTransformException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		g2.transform(T);
		//g2.scale(1, -1);
		
		g.drawImage(img, 10, 10, null);
		g.drawRect(10, 10, 100, 100);
	}
	
	public static void main(String[] args) {
		JFrame f = new JFrame();
		f.setSize(500,500);
		f.getContentPane().add(new InversYAxis());
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
	}
}
